package com.winhxd.b2c.customer.service.impl;


import com.winhxd.b2c.common.domain.customer.model.CustomerIntegralDetail;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.customer.vo.CustomerMyIntegralListVO;
import com.winhxd.b2c.customer.dao.CustomerIntegralDetailMapper;
import com.winhxd.b2c.customer.service.CustomerIntegralDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author caiyulong
 */
@Service
public class CustomerIntegralDetailServiceImpl implements CustomerIntegralDetailService {

    @Autowired
    private CustomerIntegralDetailMapper customerIntegralDetailMapper;

    @Override
    public void batchInsert(List<CustomerIntegralDetail> customerIntegralDetails) {
        customerIntegralDetailMapper.batchInsert(customerIntegralDetails);

    }
    @Override
    public PagedList<CustomerMyIntegralListVO> getMyIntegralList(Long customerId, int pageNo, int pageSize) {
        PagedList<CustomerMyIntegralListVO> pagedList = new PagedList<>();
        PageHelper.startPage(pageNo, pageSize);
        List<CustomerMyIntegralListVO> detailVO = customerIntegralDetailMapper.getMyIntegralList(customerId);
        PageInfo<CustomerMyIntegralListVO> pageInfo = new PageInfo<>(detailVO);
        pagedList.setData(pageInfo.getList());
        pagedList.setPageNo(pageInfo.getPageNum());
        pagedList.setPageSize(pageInfo.getPageSize());
        pagedList.setTotalRows(pageInfo.getTotal());
        return pagedList;
    }
}
